package com.wswy.wzcx.ui.main.common

import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.support.v7.app.AppCompatDialog
import com.wswy.wzcx.R
import com.wswy.wzcx.model.UpgradeModel
import com.wswy.wzcx.module.base.gone
import com.wswy.wzcx.module.base.onClick
import kotlinx.android.synthetic.main.upgrade_dialog.*

class UpgradeDialog (context: Context, private val upgradeModel: UpgradeModel): AppCompatDialog(context, R.style.customTransparentDialog2)  {

    var onUpgradeCallback:((UpgradeModel,Int)->Unit?)?=null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.upgrade_dialog)
        root_content.setBackgroundColor(Color.TRANSPARENT)
        tv_beta_title.text = "V${upgradeModel.versionName}"
        //tv_upgrade_info.text = "info"
        tv_beta_upgrade_feature.text = upgradeModel.updateLog

        setCanceledOnTouchOutside(false)

        if (upgradeModel.force == true){
            btn_cancel.gone()
            setCancelable(false)
        }

        var clicked = 0
        btn_confirm.onClick {
            clicked = 1
            if (upgradeModel.force == true){
                clicked = 2
                onUpgradeCallback?.invoke(upgradeModel,clicked)
            } else {
                dismiss()
            }
        }

        btn_cancel.onClick {
            dismiss()
        }

        setOnDismissListener {
            onUpgradeCallback?.invoke(upgradeModel,clicked)
        }
    }

}